package com.kingyea.mobilepolice.apimanage.camel;

import com.kingyea.camel.runtime.Service;
import com.kingyea.camel.runtime.ServiceContainer;
import com.kingyea.mobilepolice.apimanage.utils.ApplicationContextUtil;

import java.io.File;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description
 * @date Created in 2018/9/18 22:47
 */

public class KingyeaCamelService {


    public static Service loadService(String serviceDefinitionFile)throws Exception{
        Service service = null;
        ServiceContainer sc = getServiceContainer();
        if(sc.getStatus().name().equals("Stoped")){
            sc.start();
        }
        File file  = new File(serviceDefinitionFile);
        try{
            service = sc.loadService(file);
            System.out.println(" load KingyeaCamelService >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> serviceName:"+service.getServiceInfo().getServiceName());
        }catch (Exception e){
            e.printStackTrace();
        }
        return service;
    }


    public static ServiceContainer getServiceContainer(){
        ServiceContainer sc;
        if(ServiceContainer.getServiceContainer()==null){
            sc = new ServiceContainer();
            sc.setBeanFactory(ApplicationContextUtil.getContext());
        }else {
            sc = ServiceContainer.getServiceContainer();
        }
        return sc;
    }





}
